<?php
  //This has to be the first line of code a file if sessions are used.
  session_start();
  
  require_once ('check_PDO.php');
  require_once ('appinfo.php');

  //error_reporting(E_ALL & ~E_DEPRECATED);

  if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
    @date_default_timezone_set(@date_default_timezone_get());
  }
  
  if(isset($_SESSION['AppInfo'])) {
    $app = unserialize($_SESSION['AppInfo']);
    if($app->ConnURL == "") {
      header("Location: login.php"); 
      exit; 
    }
  } else {
    header("Location: login.php");
    exit; 
  }

  include_once ('init_db_connect.php');  
  require_once ('DBSchema.php');  
  require_once ('helper.php');  

  try {
    $conn_str = "cubrid:dbname=".$dbConfig['DB_DATABASE_NAME'].";host=".$dbConfig['DB_HOST'].";port=30000";
    $conn = new PDO($conn_str, $dbConfig['DB_USERNAME'], $dbConfig['DB_PASSWORD'] );
  } catch(PDOException $e) {
    header("Location: login.php"); 
  }

  $filename = "";
  $delimiter = "";
  $generate_drop = false;
  $create_file = false;
  $selected_tables = "";
  $selected_views = "";
  $selected_triggers = "";
  $selected_procedures = "";
  $selected_serials = "";
  $selected_users = "";
  $use_auto_increment = ""; 
  $generate_data = "";
  $filename_seed = "";
  
  if(isset($_POST['Execute'])) {
    foreach($_POST as $key => $value) {
      if($key == "delimiter") {
        $delimiter = $value;
        $delimiter = str_replace("\\", "", $delimiter);
      }
      if($key == "generate_drop") {
        $generate_drop = $value;
      }
      if($key == "use_auto_increment") {
        $use_auto_increment = $value;
      }
      if($key == "generate_data") {
        $generate_data = $value;
      }

      //tables
      if(strpos($key, "table_") === 0) {
        $selected_tables = $selected_tables.substr($key, strlen("table_")).",";
      }
      //views
      if(strpos($key, "view_") === 0) {
        $selected_views = $selected_views.substr($key, strlen("view_")).",";
      }
      //triggers
      if(strpos($key, "trigger_") === 0) {
        $selected_triggers = $selected_triggers.substr($key, strlen("trigger_")).",";
      }
      //procedures
      if(strpos($key, "procedure_") === 0) {
        $selected_procedures = $selected_procedures.substr($key, strlen("procedure_")).",";
      }
      //serials
      if(strpos($key, "serial_") === 0) {
        $selected_serials = $selected_serials.substr($key, strlen("serial_")).",";
      }
      //users
      if(strpos($key, "user_") === 0) {
        $selected_users = $selected_users.substr($key, strlen("user_")).",";
      }
    }

    if(strlen($selected_users) > 0) {
      $selected_users = substr($selected_users, 0, strlen($selected_users)-1);
      $create_file = true;  
    }
    if(strlen($selected_serials) > 0) {
      $selected_serials = substr($selected_serials, 0, strlen($selected_serials)-1);
      $create_file = true;  
    }
    if(strlen($selected_tables) > 0) {
      $selected_tables = substr($selected_tables, 0, strlen($selected_tables)-1);
      $create_file = true;  
    }
    if(strlen($selected_views) > 0) {
      $selected_views = substr($selected_views, 0, strlen($selected_views)-1);
      $create_file = true;  
    }
    if(strlen($selected_procedures) > 0) {
      $selected_procedures = substr($selected_procedures, 0, strlen($selected_procedures)-1);
      $create_file = true;  
    }
    if(strlen($selected_triggers) > 0) {
      $selected_triggers = substr($selected_triggers, 0, strlen($selected_triggers)-1);
      $create_file = true;  
    }
    
    if($create_file) {
      $filename = "export/db_schema_".$dbConfig['DB_DATABASE_NAME']."_".date("Y-m-d_H-i",time()).".sql";
      $fh = fopen($filename, 'w');
      
      $str = export_header($dbConfig['DB_DATABASE_NAME']);
      fwrite($fh, $str);

      $export_drops = false;
      if($generate_drop == "on") {
        $export_drops = true;
      }
      
      if(strlen($selected_users) > 0) {
        $str = export_users($conn, $selected_users, $delimiter, $export_drops);
        fwrite($fh, cleanup_SQL($str));
      }
      if(strlen($selected_serials) > 0) {
        $str = export_serials($conn, $selected_serials, $delimiter, $export_drops);
        fwrite($fh, cleanup_SQL($str));
      }
      if(strlen($selected_tables) > 0) {
        if($generate_data == "on") {
          $filename_seed = date("Y-m-d_H-i",time());
          $str = export_tables($conn, $selected_tables, $delimiter, $export_drops, $use_auto_increment, $filename_seed);
          fwrite($fh, cleanup_SQL($str));
        } else {
          $str = export_tables($conn, $selected_tables, $delimiter, $export_drops, $use_auto_increment, "");
          fwrite($fh, cleanup_SQL($str));
        }
      }
      if(strlen($selected_views) > 0) {
        $str = export_views($conn, $selected_views, $delimiter, $export_drops);
        fwrite($fh, cleanup_SQL($str));
      }
      if(strlen($selected_procedures) > 0) {
        $str = export_procedures($conn, $selected_procedures, $delimiter, $export_drops);
        fwrite($fh, cleanup_SQL($str));
      }
      if(strlen($selected_triggers) > 0) {
        $str = export_triggers($conn, $selected_triggers, $delimiter, $export_drops);
        fwrite($fh, cleanup_SQL($str));
      }
      
      $str = PHP_EOL.PHP_EOL;
      fwrite($fh, $str);

      fclose($fh);
    }
  }
  
  $tabwidth = 400;  
  $tabheight = 400; 

  $alt_row_bgcolor = "#F8F8F8"; 
?>
  
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <?php include_once ("head.php"); ?>
  <script type="text/javascript" src="js/tabber-minimized.js"></script>
  </head>
  <body>
    <div id="slowScreenSplash" style="position:absolute;z-index:5;top:40%; width: 100%;" align="center">
      <img src="images/ajax-loader.gif" alt="Loading...">
      <br /><br />
      <p style="font-weight: bold; margin: 1px; padding: 1px; color: green; width: 100%;" align="center">
        Please wait while the files are generated...
      </p>
      <br />
    </div>
    <?php include_once ("header.php"); ?>
    <form name="app" id="app" action="index.php" method="post" style="margin: 0px; padding: 0px;">
    <table>
      <tr>
        <td>&nbsp</td>
        <td width="300px" align="left" valign="top" style="border-right: silver;border-right-style: solid;border-right-width: 1px; height: <?php echo $tabheight; ?>px; margin-right: 10px;">
          <div style="float:left; border:10px; width:300px; height: 300px; margin-right: 10px;" >
            <p style="font-weight: bold; margin: 1px; padding: 1px; color: red;">Connection information</p>
            <table>
              <tr>
                <td width="80px">Database: </td>
                <td><b style="color: navy"><?php echo $dbConfig['DB_DATABASE_NAME']; ?></b></td>
                <td width="20px">&nbsp;</td>
              </tr>
              <tr>
                <td width="80px">User: </td>
                <td><b style="color: navy"><?php echo $dbConfig['DB_USERNAME']; ?></b></td>
                <td width="20px">&nbsp;</td>
              </tr>
              <tr>
                <td width="80px">Server: </td>
                <td width="100%"><b style="color: navy"><?php echo $dbConfig['DB_HOST']; ?></b></td>
                <?php
                  $script_url="conn_info.php";
                  $script_link = "<a title=\"Show more connection information\" href=\"javascript:void(0)\" onclick=\"popup_sizeable('".$script_url."', 400, 250)\">more...</a>";
                ?>              
                <td width="20px" align="right"><img src="images/conn-info.png" width="12px" height="12px"/><i><?php echo $script_link; ?></i></td>
              </tr>
            </table>
            <hr />
            <p style="font-weight: bold; margin: 1px; padding: 1px; color: red;">Script export settings</p>
            <?php 
              if($delimiter == "\"") {
                $val_delimiter = "\"";
              } else {
                $val_delimiter = $delimiter;
              }
            ?>
            Names (tables, columns etc.) delimiter: 
            <input type="text" name="delimiter" size="1" maxlength="1" value='<?php echo $val_delimiter; ?>' />
            <br />
            <?php
            $checked = "";
            if($use_auto_increment == "on") {
              $checked = "checked=\"checked\"";
            }
            ?>            
            Use current AUTO_INCREMENT values:<input type="checkbox" name="use_auto_increment" <?php echo $checked; ?> />
            <br />
            <?php
            $checked = "";
            if($generate_drop == "on") {
              $checked = "checked=\"checked\"";
            }
            ?>            
            Generate DROP statements:<input type="checkbox" name="generate_drop" <?php echo $checked; ?> />
            <br />
            <?php
            $checked = "";
            if($generate_data == "on") {
              $checked = "checked=\"checked\"";
            }
            ?>            
            Generate data exports for tables (CSV):<input type="checkbox" name="generate_data" <?php echo $checked; ?> />
            <hr />
            <input type="submit" title="Reload database schema" class="button" name="Reload" value="Reload schema" />
            &nbsp;
            <input type="submit" title="Create SQL schema script" class="button" name="Execute" value="Create script" />
            <hr />
            <?php
            if($filename != "") {
            ?>
              <p style="font-weight: bold; margin: 1px; padding: 1px; color: green;">Script generated successfully!</p>
              <a href="<?php echo $filename; ?>" target="_blank">Download SQL Script (<?php echo format_file_size(filesize($filename)); ?>)</a>
              <br />
              <br />
              <b>Exported objects:</b>
              <br />
              <div style="width: 100%; height: 150px; overflow-y: scroll;">
                <font style="font-size: 80%;">
                <?php
                //$exported_tables = split(",", $selected_tables);
                $exported_tables = explode(",", $selected_tables);
                
                foreach($exported_tables as $exp) {
                  if($exp != "") {
                    if($filename_seed != "") {
                      $file_data = "export/db_table_data_".$exp."_".$filename_seed.".csv";
                      $file_link = "<a style=\"font-size: 80%;\" href=\"".$file_data."\" target=\"_blank\">Table Data (CSV)</a>";
                      echo "<font style='color: navy;'>".$exp."</font> (<i>".$file_link."</i>)<br />";
                    } else {
                      echo "<font style='color: navy;'>".$exp."</font> (<i>table</i>)<br />";
                    }
                  }
                }  
                //$exported_views = split(",", $selected_views);
                $exported_views = explode(",", $selected_views);
                foreach($exported_views as $exp) {
                  if($exp != "") {
                    echo "<font style='color: navy;'>".$exp."</font> (<i>view</i>)<br />";
                  }
                }  
                //$exported_triggers = split(",", $selected_triggers);
                $exported_triggers = explode(",", $selected_triggers);
                foreach($exported_triggers as $exp) {
                  if($exp != "") {
                    echo "<font style='color: navy;'>".$exp."</font> (<i>trigger</i>)<br />";
                  }
                }  
                //$exported_procedures = split(",", $selected_procedures);
                $exported_procedures = explode(",", $selected_procedures);
                foreach($exported_procedures as $exp) {
                  if($exp != "") {
                    echo "<font style='color: navy;'>".$exp."</font> (<i>stored procedure</i>)<br />";
                  }
                }  
                //$exported_serials = split(",", $selected_serials);
                $exported_serials = explode(",", $selected_serials);
                foreach($exported_serials as $exp) {
                  if($exp != "") {
                    echo "<font style='color: navy;'>".$exp."</font> (<i>serial</i>)<br />";
                  }
                }  
                //$exported_users = split(",", $selected_users);
                $exported_users = explode(",", $selected_users);
                foreach($exported_users as $exp) {
                  if($exp != "") {
                    echo "<font style='color: navy;'>".$exp."</font> (<i>user</i>)<br />";
                  }
                }  
                ?>
                </font>
              </div>
            <?php
            }
            ?>            
          </div>
        </td>
        <td>&nbsp</td>
        <td align="left" valign="top" width="100%" style="margin: 50px;">
          <div class="tabber">
            <div class="tabbertab"  title="Tables">
              <div id="dbTables">
                <img src="images/all.png" width="12px" height="12px" />&nbsp;<a href="#" title="Select all objects" onclick="checkAll('table_', 'app');">Select All Tables</a>
                &nbsp;&nbsp;&nbsp;
                <img src="images/none.png" width="12px" height="12px" />&nbsp;<a href="#" title="Unselect objects" onclick="checkNone('table_', 'app');">Select None</a>
              </div>
              <hr />
              <div style="width: 100%; height: <?php echo $tabheight; ?>px; overflow-y: scroll;">
              <table>
              <?php
              $row_count = 0;
              $row_bgcolor = "#FFFFFF";
              $result = $conn->cubrid_schema(PDO::CUBRID_SCH_TABLE);
              if($result != null) {
                foreach ($result as $row) {
                  if($row["TYPE"] == 2) { //2=user tables
                    $row_count++;
                    if($row_count%2 == 0) {
                      $row_bgcolor = "#FFFFFF";
                    } else {
                      $row_bgcolor = $alt_row_bgcolor;
                    }
              ?>              
                <tr bgcolor="<?php echo $row_bgcolor; ?>">
                  <td width="10px" style="padding-left: 10px; padding-right: 10px;">
                    <?php
                    $checked = "";
                    if($selected_tables != "") {
                      if(strpos($selected_tables, $row["NAME"]) !== false) {
                        $checked = "checked=\"checked\"";
                      }
                    }
                    ?>              
                    <input type="checkbox" name="table_<?php echo $row["NAME"]; ?>" <?php echo $checked; ?> />
                    <input type="hidden" name="checkbox_table_<?php echo $row["NAME"]; ?>" value="<?php $checked; ?>"  />
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <b style="color: navy;">
                      <?php echo $row["NAME"]; ?>
                    </b>
                    &nbsp;(<font color="gray"><?php echo get_table_count($conn, $row["NAME"], $delimiter); ?> rows</font>)
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <?php
                      $script_url="object_script.php?object_type=table&object_name=".$row["NAME"]."&delimiter=".$delimiter;
                      $script_link = "<a href=\"javascript:void(0)\" onclick=\"popup('".$script_url."')\">SQL Script...</a>";
                    ?>              
                    <img src="images/script.png" width="12px" height="12px"/><i><?php echo $script_link; ?></i>
                    &nbsp;
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <?php
                      $script_url="table_info.php?object_name=".$row["NAME"];
                      $script_link = "<a href=\"javascript:void(0)\" onclick=\"popup_sizeable('".$script_url."', 300, 300)\">Table info...</a>";
                    ?>              
                    <img src="images/information.png" width="12px" height="12px"/><i><?php echo $script_link; ?></i>
                    &nbsp;
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <?php
                      $script_url="table_definition.php?table_name=".$row["NAME"];
                      $script_link = "<a href=\"javascript:void(0)\" onclick=\"popup_sizeable('".$script_url."', 800, 400)\">Table definition</a>";
                    ?>              
                    <img src="images/definition.png" width="12px" height="12px"/><i><?php echo $script_link; ?></i>
                  </td>
                </tr>                
              <?php
                  }
                }
              }  
              ?>              
              </table>
              </div>
            </div>
            <div class="tabbertab" title="Views">
              <div id="dbViews">
                <img src="images/all.png" width="12px" height="12px" />&nbsp;<a href="#" title="Select all objects" onclick="checkAll('view_', 'app');">Select All Views</a>
                &nbsp;&nbsp;&nbsp;
                <img src="images/none.png" width="12px" height="12px" />&nbsp;<a href="#" title="Unselect objects" onclick="checkNone('view_', 'app');">Select None</a>
              </div>
              <hr />
              <div style="width: 100%; height: <?php echo $tabheight; ?>px; overflow-y: scroll;">
              <table>
              <?php
              $row_count = 0;
              $row_bgcolor = "#FFFFFF";
              $result = $conn->cubrid_schema(PDO::CUBRID_SCH_VIEW);
              if($result != null) {
                foreach ($result as $row) {
                  if($row["TYPE"] == 1) { //2=user views
                    $row_count++;
                    if($row_count%2 == 0) {
                      $row_bgcolor = "#FFFFFF";
                    } else {
                      $row_bgcolor = $alt_row_bgcolor;
                    }
              ?>              
                <tr bgcolor="<?php echo $row_bgcolor; ?>">
                  <td width="10px" style="padding-left: 10px; padding-right: 10px;">
                    <?php
                    $checked = "";
                    if($selected_views != "") {
                      if(strpos($selected_views, $row["NAME"]) !== false) {
                        $checked = "checked=\"checked\"";
                      }
                    }
                    ?>              
                    <input type="checkbox" name="view_<?php echo $row["NAME"]; ?>" <?php echo $checked; ?> />
                    <input type="hidden" name="checkbox_view_<?php echo $row["NAME"]; ?>" value="<?php $checked; ?>"  />
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <b style="color: navy">
                      <?php echo $row["NAME"]; ?>
                    </b>
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <?php
                      $script_url="object_script.php?object_type=view&object_name=".$row["NAME"]."&delimiter=".$delimiter;
                      $script_link = "<a href=\"javascript:void(0)\" onclick=\"popup('".$script_url."')\">SQL Script...</a>";
                    ?>              
                    <img src="images/script.png" width="12px" height="12px"/><i><?php echo $script_link; ?></i>
                  </td>
                </tr>                
              <?php
                  }
                }
              }  
              ?>              
              </table>
              </div>
            </div>
            <div class="tabbertab" title="Triggers">
              <div id="dbTriggers">
                <img src="images/all.png" width="12px" height="12px" />&nbsp;<a href="#" title="Select all objects" onclick="checkAll('trigger_', 'app');">Select All Triggers</a>
                &nbsp;&nbsp;&nbsp;
                <img src="images/none.png" width="12px" height="12px" />&nbsp;<a href="#" title="Unselect objects" onclick="checkNone('trigger_', 'app');">Select None</a>
              </div>
              <hr />
              <div style="width: 100%; height: <?php echo $tabheight; ?>px; overflow-y: scroll;">
              <table>
              <?php
              $row_count = 0;
              $row_bgcolor = "#FFFFFF";
              $result = $conn->cubrid_schema(PDO::CUBRID_SCH_TRIGGER);
              if($result != null) {
                foreach ($result as $row) {
                  $row_count++;
                  if($row_count%2 == 0) {
                    $row_bgcolor = "#FFFFFF";
                  } else {
                    $row_bgcolor = $alt_row_bgcolor;
                  }
              ?>              
                <tr bgcolor="<?php echo $row_bgcolor; ?>">
                  <td width="10px" style="padding-left: 10px; padding-right: 10px;">
                    <?php
                    $checked = "";
                    if($selected_triggers != "") {
                      if(strpos($selected_triggers, $row["NAME"]) !== false) {
                        $checked = "checked=\"checked\"";
                      }
                    }
                    ?>              
                    <input type="checkbox" name="trigger_<?php echo $row["NAME"]; ?>" <?php echo $checked; ?> />
                    <input type="hidden" name="checkbox_trigger_<?php echo $row["NAME"]; ?>" value="<?php $checked; ?>"  />
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <b style="color: navy">
                      <?php echo $row["NAME"]; ?>
                    </b>
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <?php
                      $script_url="object_script.php?object_type=trigger&object_name=".$row["NAME"]."&delimiter=".$delimiter;
                      $script_link = "<a href=\"javascript:void(0)\" onclick=\"popup('".$script_url."')\">SQL Script...</a>";
                    ?>              
                    <img src="images/script.png" width="12px" height="12px"/><i><?php echo $script_link; ?></i>
                  </td>
                </tr>                
              <?php
                }
              }  
              ?>              
              </table>
              </div>
            </div>
            <div class="tabbertab" title="Stored Procedures">
              <div id="dbProcedures">
                <img src="images/all.png" width="12px" height="12px" />&nbsp;<a href="#" title="Select all objects" onclick="checkAll('procedure_', 'app');">Select All Procedures</a>
                &nbsp;&nbsp;&nbsp;
                <img src="images/none.png" width="12px" height="12px" />&nbsp;<a href="#" title="Unselect objects" onclick="checkNone('procedure_', 'app');">Select None</a>
              </div>
              <hr />
              <div style="width: 100%; height: <?php echo $tabheight; ?>px; overflow-y: scroll;">
              <table>
              <?php
              $row_count = 0;
              $row_bgcolor = "#FFFFFF";
              $result = $conn->query("select `sp_name`, `sp_type` from `db_stored_procedure` order by `sp_name`");
              if($result != null) {
                foreach ($result as $row) {
                  $row_count++;
                  if($row_count%2 == 0) {
                    $row_bgcolor = "#FFFFFF";
                  } else {
                    $row_bgcolor = $alt_row_bgcolor;
                  }
              ?>              
                <tr bgcolor="<?php echo $row_bgcolor; ?>">
                  <td width="10px" style="padding-left: 10px; padding-right: 10px;">
                    <?php
                    $checked = "";
                    if($selected_procedures != "") {
                      if(strpos($selected_procedures, $row["sp_name"]) !== false) {
                        $checked = "checked=\"checked\"";
                      }
                    }
                    ?>              
                    <input type="checkbox" name="procedure_<?php echo $row["sp_name"]; ?>" <?php echo $checked; ?> />
                    <input type="hidden" name="checkbox_procedure_<?php echo $row["sp_name"]; ?>" value="<?php $checked; ?>"  />
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <b style="color: navy">
                      <?php echo $row["sp_name"]; ?>
                    </b>
                    &nbsp;(<?php echo strtolower($row["sp_type"]); ?>)
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <?php
                      $script_url="object_script.php?object_type=procedure&object_name=".$row["sp_name"]."&delimiter=".$delimiter;
                      $script_link = "<a href=\"javascript:void(0)\" onclick=\"popup('".$script_url."')\">SQL Script...</a>";
                    ?>              
                    <img src="images/script.png" width="12px" height="12px"/><i><?php echo $script_link; ?></i>
                  </td>
                </tr>                
              <?php
                }
              }  
              ?>              
              </table>
              </div>
            </div>
            <div class="tabbertab" title="Serials">
              <div id="dbSerials">
                <img src="images/all.png" width="12px" height="12px" />&nbsp;<a href="#" title="Select all objects" onclick="checkAll('serial_', 'app');">Select All Serials</a>
                &nbsp;&nbsp;&nbsp;
                <img src="images/none.png" width="12px" height="12px" />&nbsp;<a href="#" title="Unselect objects" onclick="checkNone('serial_', 'app');">Select None</a>
              </div>
              <hr />
              <div style="width: 100%; height: <?php echo $tabheight; ?>px; overflow-y: scroll;">
              <table>
              <?php
              $row_count = 0;
              $row_bgcolor = "#FFFFFF";
              $result = $conn->query("select `name` from `db_serial` where `class_name` is null and `att_name` is null order by `name`");
              if($result != null) {
                foreach ($result as $row) {
                  $row_count++;
                  if($row_count%2 == 0) {
                    $row_bgcolor = "#FFFFFF";
                  } else {
                    $row_bgcolor = $alt_row_bgcolor;
                  }
              ?>              
                <tr bgcolor="<?php echo $row_bgcolor; ?>">
                  <td width="10px" style="padding-left: 10px; padding-right: 10px;">
                    <?php
                    $checked = "";
                    if($selected_serials != "") {
                      if(strpos($selected_serials, $row["name"]) !== false) {
                        $checked = "checked=\"checked\"";
                      }
                    }
                    ?>              
                    <input type="checkbox" name="serial_<?php echo $row["name"]; ?>" <?php echo $checked; ?> />
                    <input type="hidden" name="checkbox_serial_<?php echo $row["name"]; ?>" value="<?php $checked; ?>"  />
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <b style="color: navy">
                      <?php echo $row["name"]; ?>
                    </b>
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <?php
                      $script_url="object_script.php?object_type=serial&object_name=".$row["name"]."&delimiter=".$delimiter;
                      $script_link = "<a href=\"javascript:void(0)\" onclick=\"popup('".$script_url."')\">SQL Script...</a>";
                    ?>              
                    <img src="images/script.png" width="12px" height="12px"/><i><?php echo $script_link; ?></i>
                  </td>
                </tr>                
              <?php
                }
              }  
              ?>              
              </table>
              </div>
            </div>
            <div class="tabbertab" title="Users">
              <div id="dbUsers">
                <img src="images/all.png" width="12px" height="12px" />&nbsp;<a href="#" title="Select all objects" onclick="checkAll('user_', 'app');">Select All Users</a>
                &nbsp;&nbsp;&nbsp;
                <img src="images/none.png" width="12px" height="12px" />&nbsp;<a href="#" title="Unselect objects" onclick="checkNone('user_', 'app');">Select None</a>
              </div>
              <hr />
              <div style="width: 100%; height: <?php echo $tabheight; ?>px; overflow-y: scroll;">
              <table>
              <?php
              $row_count = 0;
              $row_bgcolor = "#FFFFFF";
              $result = $conn->query("select `name` from `db_user` where `name` not in ('DBA', 'PUBLIC') order by `name`;");
              if($result != null) {
                foreach ($result as $row) {
                  $row_count++;
                  if($row_count%2 == 0) {
                    $row_bgcolor = "#FFFFFF";
                  } else {
                    $row_bgcolor = $alt_row_bgcolor;
                  }
              ?>              
                <tr bgcolor="<?php echo $row_bgcolor; ?>">
                  <td width="10px" style="padding-left: 10px; padding-right: 10px;">
                    <?php
                    $checked = "";
                    if($selected_users != "") {
                      if(strpos($selected_users, $row["name"]) !== false) {
                        $checked = "checked=\"checked\"";
                      }
                    }
                    ?>              
                    <input type="checkbox" name="user_<?php echo $row["name"]; ?>" <?php echo $checked; ?> />
                    <input type="hidden" name="checkbox_user_<?php echo $row["name"]; ?>" value="<?php $checked; ?>"  />
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <b style="color: navy">
                      <?php echo $row["name"]; ?>
                    </b>
                  </td>
                  <td style="padding-left: 10px; padding-right: 10px;">
                    <?php
                      $script_url="object_script.php?object_type=user&object_name=".$row["name"]."&delimiter=".$delimiter;
                      $script_link = "<a href=\"javascript:void(0)\" onclick=\"popup('".$script_url."')\">SQL Script...</a>";
                    ?>              
                    <img src="images/script.png" width="12px" height="12px"/><i><?php echo $script_link; ?></i>
                  </td>
                </tr>                
              <?php
                }
              }  
              ?>              
              </table>
              </div>
            </div>
          </div>
        </td>
      </tr>
    </table>    
    </form>
    <?php
    $conn = null; //disconnect
    ?>  
    <script type="text/javascript">
      document.all["slowScreenSplash"].style.display = "none";        
    </script>
    <?php include_once ("cookies_check.php"); ?> 
    <?php include_once ("footer.php"); ?> 
  </body>
</html>